import { MiddlewareConsumer, Module, } from '@nestjs/common';
import { AuthModule } from './auth/app.module';
import { WebsocketModule } from './modules/websocket/websocket.module';
import { RateLimitMiddleware } from 'src/pipe/rate.limit';
import { HttpCacheModule } from 'src/common/modules/cache/http.cache.module';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { AppRequestInterceptor } from './interceptors/request';
import { AppHttpCacheInterceptor } from './interceptors/http.cache';
import { AppResponseInterceptor } from './interceptors/response';

@Module({
	imports:[
		/**http缓存模块*/
		HttpCacheModule,
		/**认证模块 */
		AuthModule,
		/**websocket模块 客户端基于socket.io-client v3.x 连接*/
		WebsocketModule,
	],
	controllers: [

	],
	providers:[
		{
			provide: APP_INTERCEPTOR,
			useClass: AppRequestInterceptor,
		},
		{
			provide: APP_INTERCEPTOR,
			useClass: AppHttpCacheInterceptor,
		},
		{
			provide: APP_INTERCEPTOR,
			useClass: AppResponseInterceptor,
		},

	]
})
export class AppModule {
	configure(consumer: MiddlewareConsumer) {
		consumer.apply(RateLimitMiddleware).forRoutes('*');
	}

}
